package Test6.Operation;

import Test6.BOOK.Book;
import Test6.BOOK.BookList;

import java.util.Scanner;

public class DelOperation implements IOperatopn{
    public void work(BookList bookList){
        System.out.println("请输入您要删除的图书:");
        Scanner sc = new Scanner(System.in);
        String finding= sc.nextLine();
        int a = bookList.getUsedSize();
        for(int i=0;i< a;i++ ){
            if(finding.compareTo(bookList.getBooks(i).getName())==0){
                System.out.println("成功找到书籍,以成功删除!");
                bookList.books[i]=null;
                for (int j = i; j < a; j++) {
                    Book[] temp = new Book[1];
                    temp[0] = bookList.books[j];
                    bookList.books[j] = bookList.books[j+1];
                    bookList.books[j+1] = temp[0];
                    a--;
                }
                bookList.setUsedSize(a);
            } else{
                System.out.println("很抱歉!没有名为"+finding+"的书!");
            }
        }
        new OutSystem().outSystem();
    }
}
